import Singleton from "../net/Singleton";
import { Msg } from "./msg";

/**
 * proto数据解析
 */
export class ProtoDataParse extends Singleton {
    private _root: any = Msg;

    /**
     * 序列化
     * @param  req
     * @param  data
     * @returns 
     */
     encode(req: string, data: any) {
        let arryUti = this._root[req].encode(data).finish();
        return arryUti;
    }

    /**
     * 反序列化
     * @param  infoEncodeMessage 
     * @param  data
     * @returns 
     */
    decode(req: string, data: any) {
        let infoUnSerialized = this._root[req].decode(data);
        return infoUnSerialized;
    }
}